﻿/* 
 * 本文件功能：  *
 * 处理卷事件和文件系统控制事件    *
*/
#include "stdafx.h"


NTSTATUS FBFSFileSysControl(IN PDEVICE_OBJECT DriverObject, IN PIRP IRPMess){
	PIO_STACK_LOCATION irpstack = IoGetCurrentIrpStackLocation(IRPMess);
	NTSTATUS status = STATUS_UNSUCCESSFUL;
	__try{
		switch (irpstack->MinorFunction)
		{
			case IRP_MN_MOUNT_VOLUME:
				KEVENT SyncEvent;
				KeInitializeEvent(&SyncEvent,SynchronizationEvent,FALSE);
				Judge_Disk Result;
				UNICODE_STRING LowDev = RTL_CONSTANT_STRING(L"\\Device\\FBFS_DiskFilter");
				PFILE_OBJECT LowDevFileObj;
				status = IoGetDeviceObjectPointer(&LowDev,FILE_ALL_ACCESS,&LowDevFileObj,&LowerControl);
				if (NT_SUCCESS(status)){
					*((PULONG)NULL) = 0;
				}
				IO_STATUS_BLOCK IO_STK;
				PIRP NO_FREE ControlIRP = IoBuildDeviceIoControlRequest(IOCTL_JUGDE_FBINST_DISK,LowerControl,irpstack->Parameters.MountVolume.DeviceObject,sizeof(DEVICE_OBJECT),&Result,sizeof(Judge_Disk),FALSE,&SyncEvent,&IO_STK);
				status = IoCallDriver(LowerControl,ControlIRP);
				if (status==STATUS_PENDING)
				{
					KeWaitForSingleObject(&SyncEvent,UserRequest,KernelMode,FALSE,NULL);
				}
				KeSetEvent(&SyncEvent,IO_NO_INCREMENT,FALSE);
				break;
		}
	}
	__except(EXCEPTION_EXECUTE_HANDLER){
		IRPMess->IoStatus.Status = status;
		IRPMess->IoStatus.Information = 0;
		IoCompleteRequest(IRPMess,IO_NO_INCREMENT);
		return status;
	}
	return status;
}